<?php
require_once '../DTO/ChiTietTinhRaoVat.php';
require_once 'DBConnection.php';

class ChiTietTinhRaoVatDAO extends DBConnection{
	public function __construct(){
		parent::__construct();
	}
	
	//Lấy danh sách tất cả chitiettinhraovat
	public function getAllCTTRV(){
		$sql = "select * from chitiettinhraovat";
		
		$res = mysql_query($sql, $this->hDB);
		
		if(!$res){
			die("Failed getting chi tiet tinh rao vat");
		}
		
		if(mysql_num_rows($res)){
			$objs = array();
			$temp = mysql_fetch_assoc($res);
			while ($temp){
				$objs[] = new ChiTietTinhRaoVat($temp['MaTRV'], $temp['MaTinh']);
				$temp = mysql_fetch_assoc($res);
			}
			return $objs;
		}else{
			return null;
		}
	}
	
	//Insert into chitiettinhraovat
	public function insert(ChiTietTinhRaoVat $cttrv){
		$maTRV = $cttrv->getMaTRV();
		$maTinh = $cttrv->getMaTinh();
		
		$sql = "insert into chitiettinhraovat (MaTRV, MaTinh) values ('$maTRV', '$maTinh')";
		
		$res = mysql_query($sql);
		
		if(!$res){
			die("Failed insert into chitiettinhraovat");
		}
	}
	
	
}















